<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         function test(list,val) {
           const map = new Map()
        //    console.log(map);
            list.forEach(item => {
                if(map.has(item.pid)){
                    map.get(item.pid).push(item)
                }else{
                    map.set(item.id) = item
                }
            })
            console.log(map);
        }
        var arr = [
            { id: 1, name: '总裁办', pid: 0 },
            { id: 11, name: '秘书处', pid: 1 },
            { id: 2, name: 'IT部', pid: 0 }
        ]
        test(arr,0)
    </script>
</body>
</html>